#include "stdafx.h"
#include "Box2DRenderer.h"

namespace ZeEngine
{
    Box2DRenderer::Box2DRenderer(float ratio) : m_ratio(ratio)
    {
    }

    void Box2DRenderer::SetOffset(const Vector2D<s32>& offset)
    {
        m_offset = offset;
    }

    void Box2DRenderer::DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color)
    {
        /*
        if(!hge) return;

        //hge->Gfx_BeginScene();
        hge->Gfx_RenderLine( p1.x * PTM_RATIO,  p1.y * PTM_RATIO,  p2.x * PTM_RATIO,  p2.y * PTM_RATIO, ARGB(255,color.r*255,color.g*255,color.b*255));
        //hge->Gfx_EndScene();
        */
    }


    void Box2DRenderer::DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color)
    {
        /*
       if(!hge) return;

       radius *= PTM_RATIO;
       int NUMPOINTS = 24+(int)radius/20;//24;
       const float PI = 3.14159f;

       std::vector<b2Vec2> vertices;
       //hgeVector Circle[NUMPOINTS + 1];
       int i;//,j;
       float X;
       float Y;
       float Theta;
       float WedgeAngle;   //Size of angle between two points on the circle (single wedge)

       //Precompute WedgeAngle
       WedgeAngle = (float)((2*PI) / NUMPOINTS);

       //Set up vertices for a circle
       //Used <= in the for statement to ensure last point meets first point (closed circle)
       for(i=0; i<=NUMPOINTS; i++)
       {
          //Calculate theta for this vertex
          Theta = i * WedgeAngle;
      
          //Compute X and Y locations
          X = (float)((center.x * PTM_RATIO) + radius * cos(Theta));
          Y = (float)((center.y * PTM_RATIO) - radius * sin(Theta));

          vertices.push_back(b2Vec2(X, Y));//Circle[i] = hgeVector(X, Y);
       }

       //hge->Gfx_BeginScene();

       for (int32 k = 0, j = 1; k < (signed)vertices.size(); ++k, ++j)
       {
          //glVertex2f(vertices[i].x, vertices[i].y);
          j = (j>=(signed)vertices.size())?0:j;
          hge->Gfx_RenderLine(vertices[k].x, vertices[k].y, vertices[j].x, vertices[j].y, ARGB(200,color.r*128,color.g*128,color.b*128));
       }
       //hge->Gfx_EndScene();
       */
    }

    void Box2DRenderer::DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color)
    {
        /*
        if(!hge) return;
        radius *= PTM_RATIO;

        int NUMPOINTS = 24+(int)radius/20;//24;
        const float PI = 3.14159f;

        std::vector<b2Vec2> vertices;
        //hgeVector Circle[NUMPOINTS + 1];
        int i;//,j;
        float X;
        float Y;
        float Theta;
        float WedgeAngle;   //Size of angle between two points on the circle (single wedge)

        //Precompute WedgeAngle
        WedgeAngle = (float)((2*PI) / NUMPOINTS);

        //Set up vertices for a circle
        //Used <= in the for statement to ensure last point meets first point (closed circle)
        for(i=0; i<=NUMPOINTS; i++)
        {
            //Calculate theta for this vertex
            Theta = i * WedgeAngle;
      
            //Compute X and Y locations
            X = (float)((center.x * PTM_RATIO) + radius * cos(Theta));
            Y = (float)((center.y * PTM_RATIO)- radius * sin(Theta));

            vertices.push_back(b2Vec2(X, Y));//Circle[i] = hgeVector(X, Y);
        }

        //hge->Gfx_BeginScene();
        for (int32 k = 0, j = 1; k < (signed)vertices.size(); ++k, ++j)
        {
            //glVertex2f(vertices[i].x, vertices[i].y);
            j = (j>=(signed)vertices.size())?0:j;
            hge->Gfx_RenderLine(vertices[k].x, vertices[k].y, vertices[j].x, vertices[j].y, ARGB(255,color.r*255,color.g*255,color.b*255));
        }
        //hge->Gfx_EndScene();
        */
    }

    void Box2DRenderer::DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) 
    {
        /*
        if(!hge) return;

        //hge->Gfx_BeginScene();
        for (int32 i = 0, j = 1; i < vertexCount; ++i, j++)
        {
            //glVertex2f(vertices[i].x, vertices[i].y);
            j = (j>=vertexCount)?0:j;
            hge->Gfx_RenderLine(vertices[i].x * PTM_RATIO, vertices[i].y * PTM_RATIO, vertices[j].x * PTM_RATIO, vertices[j].y * PTM_RATIO, ARGB(255,color.r*255,color.g*255,color.b*255));
        }
        //hge->Gfx_EndScene();
        */
    }

    void Box2DRenderer::DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) 
    {      
        /*
       if(!hge) return;

        //hge->Gfx_BeginScene();
        for (int32 i = 0, j = 1; i < vertexCount; ++i, j++)
        {
            //glVertex2f(vertices[i].x, vertices[i].y);
            j = (j>=vertexCount)?0:j;
            hge->Gfx_RenderLine(vertices[i].x * PTM_RATIO - m_offset.GetX(), 
                                vertices[i].y * PTM_RATIO - m_offset.GetY(), 
                                vertices[j].x * PTM_RATIO - m_offset.GetX(), 
                                vertices[j].y * PTM_RATIO - m_offset.GetY(), ARGB(255,color.r*255,color.g*0,color.b*0));
        }
        //hge->Gfx_EndScene();
        */
    }
}